package com.lazyJr.test.sort;

/**
 * Created by liuyangfx on 16-3-14.
 */
public class InsertionSort {
    public void sort(int[] a){

        for(int i=1;i<a.length;i++){
            for(int j=i;j>0;j--){
                if(less(a[j],a[j-1])){
                    exch(a,j,j-1);
                }
                else break;
            }
        }
    }

    private boolean less(int v,int w){
        return (v - w) < 0;
    }

    private void exch(int[] a,int i,int j){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

}
